<?php

namespace app\index\controller;

use app\common\controller\Frontend;

class Video extends Frontend
{

    public $model       = null;
    public $classify    = null;
    public function _initialize()
    {
        parent::_initialize();
        $this->model    = new \app\admin\model\video\Content;
        $this->classify = new \app\admin\model\video\Classify;
    }

    public function index($cid = null)
    {
        $classify   = $this->classify->order('weigh desc,id desc')->select();
        if (!$cid)
            $cid = $classify[0]['id'];
        $list = $this->model->where('classify_id', $cid)->order('weigh desc,id desc')->paginate(16);
        $this->view->assign('list', $list);
        $this->view->assign('pages', $list->render());
        $this->view->assign('classify', $classify);
        $this->view->assign('classifyCount', count($classify));
        $this->view->assign('cid', $cid);
        $this->view->assign('video_description', config('site.video_description'));
        return $this->view->fetch();
    }

    public function detail($ids = null)
    {
        $row = $this->model->where('id', $ids)->find();
        $this->model->where('id', $ids)->setInc('hits');

        $current = $row['title'];

        $this->view->assign('row', $row);
        $this->view->assign('current', $current);
        return $this->view->fetch();
    }

    public function search($text = '')
    {
        $model = new \app\admin\model\video\Content;
        $list = $model->where('title', 'like', '%'.$text.'%')->paginate(10);
        $this->view->assign('list', $list);
        $this->view->assign('pages', $list->render());
        $this->view->assign('text', $text);
        return $this->view->fetch();
    }
}
